import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { /* 首页页面 */
    path: '/HomeView',
    name: 'HomeView',
    component: () => import('@/views/HomeView'),
    children: [
      { /* 个人信息页面 */
        path: '/PersonInfo',
        name: 'PersonInfo',
        component: () => import('@/views/PersonInfo')
      },
      { /* 修改密码页面 */
        path: '/UpdatePasswordView',
        name: 'UpdatePasswordView',
        component: () => import('@/views/UpdatePasswordView')
      },
      { /* 后台用户页面 */
        path: '/UserView',
        name: 'UserView',
        component: () => import('@/views/BackManage/UserView')
      },
      { /* 后台角色页面 */
        path: '/RoleView',
        name: 'RoleView',
        component: () => import('@/views/BackManage/RoleView')
      },
      { /* 后台菜单页面 */
        path: '/MenuView',
        name: 'MenuView',
        component: () => import('@/views/BackManage/MenuView')
      },
      // 用户购买会员记录 gpd 2022-10-12 10点43分
      {
        path: '/memberRecord',
        name: 'MemberRecord',
        component: () => import('@/views/MemberManage/MemberRecord')
      },
      // 会员类型 gpd 2022-10-12 11点25分
      {
        path: '/memberType',
        name: 'MemberType',
        component: () => import('@/views/MemberManage/MemberType')
      },
      // 会员价格管理 gpd 2022-10- 12 14点45分
      {
        path: '/memberPrice',
        name: 'MemberPrice',
        component: () => import('@/views/MemberManage/MemberPrice')
      },
      // 骑手审批管理 hbx 2022年10月14日10:59:17
      {
        path: '/auditView',
        name: 'AuditView',
        component: () => import('@/views/ExamineManage/AuditView')
      },
      // 商家审批管理 cjl 2022年10月18日10:27:42
      {
        path: '/MerchantView',
        name: 'MerchantView',
        component: () => import('@/views/ExamineManage/MerchantView')
      },
      { /* 前台用户页面 */
        path: '/FrontUserView',
        name: 'FrontUserView',
        component: () => import('@/views/FrontDeskManage/FrontUserView')
      },
      { /* 前台商家页面 */
        path: '/FrontMerchantView',
        name: 'FrontMerchantView',
        component: () => import('@/views/FrontDeskManage/FrontMerchantView')
      },
      { /* 前台骑手页面 */
        path: '/FrontHorsemanView',
        name: 'FrontHorsemanView',
        component: () => import('@/views/FrontDeskManage/FrontHorsemanView')
      },
      { /* 前台店铺页面 */
        path: '/FrontShopView',
        name: 'FrontShopView',
        component: () => import('@/views/FrontDeskManage/FrontShopView')
      },
      { /* 前台店铺回复页面 */
        path: '/FrontShopReplyView',
        name: 'FrontShopReplyView',
        component: () => import('@/views/FrontDeskManage/FrontShopReplyView')
      },
      { /* 店铺审批页面 */
        path: '/ShopApprovalView',
        name: 'ShopApprovalView',
        component: () => import('@/views/ExamineManage/ShopApprovalView')
      },
      { /* 订单申诉页面 */
        path: '/ShopAppealView',
        name: 'ShopAppealView',
        component: () => import('@/views/FrontDeskManage/ShopAppealView')
      },
      { /* 吃货卡类型管理页面 */
        path: '/FoodieCardTypeView',
        name: 'FoodieCardTypeView',
        component: () => import('@/views/FoodieCard/FoodieCardTypeView')
      },
      { /* 吃货卡价钱管理页面 */
        path: '/FoodieCardPriceView',
        name: 'FoodieCardPriceView',
        component: () => import('@/views/FoodieCard/FoodieCardPriceView')
      },
      { /* 吃货卡用户记录页面 */
        path: '/FoodieCardUserRecordView',
        name: 'FoodieCardUserRecordView',
        component: () => import('@/views/FoodieCard/FoodieCardUserRecordView')
      },
      { /* 吃货豆管理页面 */
        path: '/FoodieBeanView',
        name: 'FoodieBeanView',
        component: () => import('@/views/Coupon/FoodieBeanView')
      },
      { /* 优惠劵管理页面 */
        path: '/CouponView',
        name: 'CouponView',
        component: () => import('@/views/Coupon/CouponView')
      },
      { /* 优惠劵用户记录页面 */
        path: '/CouponUserRecordView',
        name: 'CouponUserRecordView',
        component: () => import('@/views/Coupon/CouponUserRecordView')
      },
      { /* 优惠劵用户使用记录页面 */
        path: '/CouponUserRecordUseView',
        name: 'CouponUserRecordUseView',
        component: () => import('@/views/Coupon/CouponUserRecordUseView')
      },
      { /* 直播列表展示 */
        path: '/ListLive',
        name: 'ListLive',
        component: () => import('@/views/Live/ListLive')
      },
      { /* 开启直播 */
        path: '/SaveLive',
        name: 'SaveLive',
        component: () => import('@/views/Live/SaveLive')
      },
      { /* 观众测试页面 */
        path: '/Gz',
        name: 'Gz',
        component: () => import('@/views/Live/Gz')
      },
      { /* 主播测试页面 */
        path: '/Zhubo',
        name: 'Zhubo',
        component: () => import('@/views/Live/Zhubo')
      },
      { /* 阿里云oss测试 */
        path: '/Aliyuoss',
        name: 'Aliyuoss',
        component: () => import('@/views/aliyuoss/Aliyuoss')
      },
    ]
  },
  {
    path: '/',
    name: 'LoginView',
    component: () => import('@/views/LoginView')
  },
  { /* 观看直播详细页面 */
  path: '/LiveDetail',
  name: 'LiveDetail',
  component: () => import('@/views/Live/LiveDetail')
},
]

const router = new VueRouter({
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next()
  } else {
    const token = window.sessionStorage.getItem('token')
    if (token) {
      next()
    } else {
      next('/')
    }
  }
})

// 解决连续点击同一导航栏，控制台报红的错误
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
